<?php
require("/usr/share/php/libphp-phpmailer/class.phpmailer.php");

class TSendMail {
	
	public function __construct(){

	}

	public static function sendEmailToUserCreated($nom, $prenom, $emailTo, $subject, $message) {
		$sm = new TSendMail();
		$mail = new PHPMailer(true);

		$mail->IsSMTP(); // telling the class to use SMTP

		try {
  			$mail->Host       = "tacks.fr"; // SMTP server
  			$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  			$mail->SMTPAuth   = true;                  // enable SMTP authentication
  			$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
  			$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  			$mail->Port       = 587;                   // set the SMTP port for the GMAIL server
  			$mail->Username   = "tacks.domotique@gmail.com";  // GMAIL username
  			$mail->Password   = "T4cks.rie";            // GMAIL password
 	 		$mail->AddReplyTo('tacks.domotique@gmail.com', 'Tacks - noreply');
  			$mail->AddAddress("$emailTo", "$nom $prenom");
  			$mail->SetFrom('tacks.domotique@gmail.com', 'Tacks - noreply');
  			$mail->AddReplyTo('tacks.domotique@gmail.com', 'Tacks - noreply');
  			$mail->Subject = "$subject";
  			$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  			$mail->MsgHTML("$message");
  			$mail->Send();
  			echo "Message Sent OK<p></p>\n";
		} catch (phpmailerException $e) {
  			echo $e->errorMessage(); //Pretty error messages from PHPMailer
		} catch (Exception $e) {
  			echo $e->getMessage(); //Boring error messages from anything else!
		}
	}
}
?>
